package com.mt.operation.service.model;

import java.util.List;
import java.util.Map;

import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;

import com.github.pagehelper.PageHelper;
import com.mt.common.PagerInfo;
import com.mt.common.ServiceResult;
import com.mt.operation.entity.ArticleReviewLogEntity;
import com.mt.operation.mapper.ArticleReviewLogEntityMapper;

@Component
public class ArticleReviewLogServiceModel {
    private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(ArticleReviewLogServiceModel.class);

    @Autowired
    private ArticleReviewLogEntityMapper articleReviewLogEntityMapper;

    public ServiceResult<List<ArticleReviewLogEntity>> selectList(Map<String, Object> params, PagerInfo<?> pagerInfo) {
        Assert.notNull(this.articleReviewLogEntityMapper, "Property 'articleReviewLogEntityMapper' is required.");
        ServiceResult<List<ArticleReviewLogEntity>> result = new ServiceResult<List<ArticleReviewLogEntity>>();
        try {
            if (pagerInfo != null) {
                PageHelper.startPage(pagerInfo.getPageIndex(), pagerInfo.getPageSize());
            }

            result.setResult(this.articleReviewLogEntityMapper.selectList(params));
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage("Unknown error!");
            LOGGER.error("[ArticleReviewLogServiceModel][selectList]：query selectList occur exception", e);
        }
        return result;
    }

    public ServiceResult<Integer> selectCount(Map<String, Object> params) {
        Assert.notNull(this.articleReviewLogEntityMapper, "Property 'articleReviewLogEntityMapper' is required.");
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        try {
            result.setResult(this.articleReviewLogEntityMapper.selectCount(params));
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage("Unknown error!");
            LOGGER.error("[ArticleReviewLogServiceModel][selectInfo]：query selectInfo occur exception", e);
        }
        return result;
    }

    public ServiceResult<ArticleReviewLogEntity> selectInfo(Map<String, Object> params) {
        Assert.notNull(this.articleReviewLogEntityMapper, "Property 'articleReviewLogEntityMapper' is required.");
        ServiceResult<ArticleReviewLogEntity> result = new ServiceResult<ArticleReviewLogEntity>();
        try {
            result.setResult(this.articleReviewLogEntityMapper.selectByPrimaryKey(params));
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage("Unknown error!");
            LOGGER.error("[ArticleReviewLogServiceModel][selectInfo]：query selectInfo occur exception", e);
        }
        return result;
    }

    public ServiceResult<Integer> insert(ArticleReviewLogEntity articleReviewLogEntity) {
        Assert.notNull(this.articleReviewLogEntityMapper, "Property 'articleReviewLogEntityMapper' is required.");
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        int id = 0;
        try {
            int save = this.articleReviewLogEntityMapper.insert(articleReviewLogEntity);
            if (save > 0) {
                id = articleReviewLogEntity.getReviewLogId();
            }
            result.setResult(id);
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage("Unknown error!");
            LOGGER.error("[ArticleReviewLogServiceModel][insert]：query insert occur exception", e);
        }
        return result;
    }

    public ServiceResult<Integer> updateRelate(ArticleReviewLogEntity articleReviewLogEntity) {
        Assert.notNull(this.articleReviewLogEntityMapper, "Property 'articleReviewLogEntityMapper' is required.");
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        int id = 0;
        try {
            int save = this.articleReviewLogEntityMapper.updateByPrimaryKeySelective(articleReviewLogEntity);
            if (save > 0) {
                id = articleReviewLogEntity.getReviewLogId();
            }
            result.setResult(id);
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage("Unknown error!");
            LOGGER.error("[ArticleReviewLogServiceModel][updateByPrimaryKeySelective]:query update occur exception", e);
        }
        return result;
    }

    public ServiceResult<Integer> updateByPrimaryKeySelective(ArticleReviewLogEntity articleReviewLogEntity) {
        Assert.notNull(this.articleReviewLogEntityMapper, "Property 'articleReviewLogEntityMapper' is required.");
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        int id = 0;
        try {
            int save = this.articleReviewLogEntityMapper.updateByPrimaryKeySelective(articleReviewLogEntity);
            if (save > 0) {
                id = articleReviewLogEntity.getReviewLogId();
            }
            result.setResult(id);
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage("Unknown error!");
            LOGGER.error("[ArticleReviewLogServiceModel][updateByPrimaryKeySelective]:query update occur exception", e);
        }
        return result;
    }

    public ServiceResult<Integer> deleteByPrimaryKey(Integer reviewLogId) {
        Assert.notNull(this.articleReviewLogEntityMapper, "Property 'articleReviewLogEntityMapper' is required.");
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        int save = 0;
        try {
            save = this.articleReviewLogEntityMapper.deleteByPrimaryKey(reviewLogId);
            result.setResult(save);
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage("Unknown error!");
            LOGGER.error("[ArticleReviewLogServiceModel][updateByPrimaryKeySelective]:query update occur exception", e);
        }
        return result;
    }
}
